package com.manager.controller;

import com.manager.bean.ClassInfo;
import com.manager.service.ClassInfoService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;
import java.util.List;

import com.manager.bean.PageInfo;

/**
 * (ClassInfo)表控制层
 *
 * @author makejava
 * @since 2021-03-02 20:15:29
 */
@Controller
public class ClassInfoController {
    /**
     * 服务对象
     */
    @Resource
    private ClassInfoService classInfoService;

    @RequestMapping(value = "/findClassInfo")
    public String findClassInfo(Model model,Integer Id, String Name, String Counsellor, String CounselorPhone, Integer pageIndex, Integer pageSize) {
        PageInfo<ClassInfo> pi =  classInfoService.findPageInfo(Id,Name,Counsellor,CounselorPhone,pageIndex,pageSize);
        model.addAttribute("pi", pi);
        return "classInfo_list";
    }


    @RequestMapping(value = "/exportclassInfolist", method = RequestMethod.POST)
    @ResponseBody
    public List<ClassInfo> exportClassInfo() {
        List<ClassInfo> classInfoList = classInfoService.getAll();
        return classInfoList;
    }


    @RequestMapping("/deleteClassInfo")
    @ResponseBody
    public String deleteClassInfo(Integer Id) {
        classInfoService.deleteById(Id);
        return "classInfo_list";
    }


    @RequestMapping(value = "/addClassInfo", method = RequestMethod.POST)
    @ResponseBody
    public String addClassInfo(@RequestBody ClassInfo classInfo) {
        classInfoService.insert(classInfo);
        return "classInfo_list";
    }


    @RequestMapping(value = "/updateClassInfo", method = RequestMethod.POST)
    public String updateClassInfo(ClassInfo classInfo) {
        classInfoService.update(classInfo);
        return "redirect:/findClassInfo";
    }


    @RequestMapping("/findClassInfoById")
    public String findClassInfoById(Integer Id, HttpSession session, Model model) {
        ClassInfo s = classInfoService.queryById(Id);
        session.setAttribute("s", s);
        model.addAttribute("s", s);
        return "classInfo_edit";
    }

}
